package org.study.opensearch.boot.config;

import org.apache.hc.client5.http.impl.async.HttpAsyncClientBuilder;
import org.opensearch.client.RestClientBuilder;
import org.opensearch.spring.boot.autoconfigure.RestClientBuilderCustomizer;
import org.springframework.context.annotation.*;
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
import org.study.opensearch.boot.repository.ProductRepository;

/**
 * 作用描述
 *
 * @author doveylovey
 * @version v1.0.0
 * @email 1135782208@qq.com
 * @date 2025年05月09日
 */
@Configuration
@EnableElasticsearchRepositories(basePackageClasses = ProductRepository.class)
@ComponentScan(basePackageClasses = OpenSearchConfig.class)
public class OpenSearchConfig {
    /**
     * Allow to connect to the OpenSearch instance which uses self-signed certificates
     */
    @Bean
    public RestClientBuilderCustomizer customizer() {
        return new RestClientBuilderCustomizer() {
            @Override
            public void customize(HttpAsyncClientBuilder builder) {
                /*try {
                    builder.setSSLContext(new SSLContextBuilder()
                            .loadTrustMaterial(null, new TrustSelfSignedStrategy())
                            .build());
                } catch (final KeyManagementException | NoSuchAlgorithmException | KeyStoreException ex) {
                    throw new RuntimeException("Failed to initialize SSL Context instance", ex);
                }*/
            }

            @Override
            public void customize(RestClientBuilder builder) {
                // No additional customizations needed
            }
        };
    }
}
